package com.wxcms.ctrl;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.wxcms.domain.DepEquipments;
import com.wxcms.domain.WxProvinceDesc;
import com.wxcms.mapper.WxProvinceDescDao;

import net.sf.json.JSONArray;

@Controller
@RequestMapping("/super")
public class SuperCtrl {
	@Autowired
	private WxProvinceDescDao wxproDescDao;
	/**
	 * 读取所有配置的企业号信息
	 * */
	@RequestMapping(value = "/provincepage")
	public ModelAndView provincepage(HttpServletRequest request) {

		ModelAndView modelAndView = new ModelAndView("super/province");

		return modelAndView;
	}
	
	
	/**
	 * 读取所有配置的企业号信息
	 * */
	@RequestMapping(value = "/provincejson" )
	public @ResponseBody JSONArray provincejson(HttpServletRequest request) {

        JSONArray json=new JSONArray();
		List<WxProvinceDesc> items = wxproDescDao.getall();
 
		json=JSONArray.fromObject(items);

		 return json;
	}
	/**
	 * 读取所有配置的企业号信息
	 * */
	@RequestMapping(value = "/saveprivince" )
	public @ResponseBody JSONObject saveprivince(@RequestBody List<WxProvinceDesc> infos) {
	    JSONObject jsobj= new JSONObject();
		
			try {
			     wxproDescDao.updateInfo(infos);;
			    jsobj.put("success", true);
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			    jsobj.put("success", false);
			}
		   
        return  jsobj;
 
	}
}
